IF EXISTS (SELECT * FROM sysobjects WHERE name = 'SelectCommandFacultad' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.SelectCommandFacultad
GO

CREATE PROCEDURE dbo.SelectCommandFacultad
AS
	SET NOCOUNT ON;
select *FROM facultad
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandFacultad' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.InsertCommandFacultad
GO

CREATE PROCEDURE dbo.InsertCommandFacultad
(
	
	@nombre nchar(100)
)
AS
DECLARE @ID INT
SET @ID = (SELECT MAX(codigo) FROM [Facultad])  
                                                                                                                                                                                                            
IF @ID IS NULL OR @ID=0                                                                                                                                                                                                                           
	SET @ID = 1                                                                                                                                                                                                                                      
ELSE                                                                                                                                                                                                                                                            
 SET @ID = @ID + 1  

	SET NOCOUNT OFF;
INSERT INTO [facultad] ([codigo], [nombre]) VALUES (@id, @nombre)
GO

